package job1;
//编写一个员工类   (1)属性: 姓名,年龄       如果年龄小于18龄大于150抛出年龄异常       如果姓名为null或者""抛出空异常
public class Staff {
    private String name;
    private int age;

    public Staff(String name, int age) throws AgeIllegalException, NameEmptyException {
        setName(name);
        setAge(age);
    }

    public void setAge(int age) throws AgeIllegalException {
        if (age < 18 || age > 150)
            throw new AgeIllegalException("合法的年龄段为[18,150]");
        this.age = age;
    }

    public void setName(String name) throws NameEmptyException {
        if (null == name || 0 == name.length())
            throw new NameEmptyException("姓名不能为空");
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
